﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IFDB.Models.Tables;

namespace IFDB.Models.Contexts
{
    public class IFDBContext : DbContext
    {
        public IFDBContext()
            : base("name=IFDBContext")
        {
        }

        public DbSet<AppearanceEvent> AppearanceEvents { get; set; }
        public DbSet<Competition> Competitions { get; set; }
        public DbSet<LookupMatch> LookupMatches { get; set; }
        public DbSet<LookupPerson> LookupPersons { get; set; }
        public DbSet<LookupTeam> LookupTeams { get; set; }
        public DbSet<LookupVenue> LookupVenues { get; set; }
        public DbSet<Match> Matches { get; set; }
        public DbSet<Person> Persons { get; set; }
        public DbSet<Season> Seasons { get; set; }
        public DbSet<TeamBadge> TeamBadges { get; set; }
        public DbSet<TeamName> TeamNames { get; set; }
        public DbSet<Team> Teams { get; set; }
        public DbSet<Venue> Venues { get; set; }
        public DbSet<UserProfile> UserProfiles { get; set; }
        public DbSet<Membership> Memberships { get; set; }
        public DbSet<Role> Roles { get; set; }
        public DbSet<UsersInRole> UsersInRoles { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            modelBuilder.Entity<Match>()
                .HasRequired(a => a.Team1)
                .WithMany()
                .HasForeignKey(u => u.Team1Id).WillCascadeOnDelete(false);

            modelBuilder.Entity<Match>()
                .HasRequired(a => a.Team2)
                .WithMany()
                .HasForeignKey(u => u.Team2Id).WillCascadeOnDelete(false);
        }
    }
}
